<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2017/3/15
 * Time: 10:59
 */

namespace SDXApi\Model;


use Think\Model;

/**
 * Class AlbumModel
 * @package SDXApi\Model
 */
class AlbumModel extends Model
{
	/**
	 * @var string
	 */
	protected $tableName = 'album';

	/**
	 * Created by Jerry
	 * @return mixed
	 */
	public function findAlbumList()
	{
		return $this->select();
	}

    /**
     * @author Jerry
     * @return mixed
     */
    public function findAlbums()
    {
        $time = time();
        $where = array(
            'start_time'=>	array('LT', $time,),
            'end_time'	=>	array('GT', $time,),
        );

        return $this->where($where)->select();
    }

	/**
	 * Created by Jerry
	 * @param int $id
	 * @return mixed
	 */
	public function findAlbumById($id = 0)
	{
		$where = array(
			'id'	=>	$id,
		);

		return $this->where($where)->find();
	}


	/**
	 * Created by Jerry
	 * @param int $id
	 * @return mixed
	 */
	public function findAlbumCoverByAlbumId($id = 0)
	{
		$where = array(
			't.album_id'	=>	$id,
			't.type'		=>	2,
		);

		return $this->table('sdx_album_template')
						->alias('t')
						->join('LEFT JOIN __ALBUM_TEMPLATE_GOODS__ AS tg ON t.id = tg.template_id')
						->join('LEFT JOIN __GOODS__ AS g ON tg.goods_id = g.goods_id')
						->where($where)
						->getField('g.original_img');
	}
}